package node.block.stmt;

import midcode.MidCode;
import midcode.MidcodeGenerator;
import midcode.OPType;
import node.Node;
import node.exp.Exp;
import symbol.Function;


public class ReturnStmt implements Node {
    private Exp exp;
    private Function function;

    public ReturnStmt(Exp exp, Function function) {
        this.exp = exp;
        this.function = function;
    }

    @Override
    public Node getFather() {
        return father;
    }

    @Override
    public String genMidCode() {
        MidcodeGenerator mg = MidcodeGenerator.getInstance();
        if (!function.getName().equals("main")) {
            if (exp == null) {
                mg.addMidcode(new MidCode(OPType.RET_VOID, null, null, null));
            } else {
                mg.addMidcode(new MidCode(OPType.RET_INT, null, null, exp.genMidCode()));
            }
        }
        return "";
    }
}

